from flasks import Flask, render_template
from flaskProject.flaskDemo import config
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config.from_object(config)
db = SQLAlchemy(app)


class bar_1(db.Model):
    __tablename__ = "bar_1"

    id = db.Column(db.Integer, primary_key=True)
    x_lable = db.Column(db.VARCHAR(45), primary_key=False)
    x = db.Column(db.Integer, primary_key=False)
    y = db.Column(db.Integer, primary_key=False)


db.create_all()


@app.route('/')
def hello_world():
    # barPojo1 = bar_1(id=1, x_lable="one", x=1, y=1)
    # barPojo2 = bar_1(id=2, x_lable="two", x=2, y=2)
    # barPojo3 = bar_1(id=3, x_lable="three", x=3, y=3)
    # barPojo4 = bar_1(id=4, x_lable="four", x=4, y=4)
    # db.session.add(barPojo1)
    # db.session.add(barPojo2)
    # db.session.add(barPojo3)
    # db.session.add(barPojo4)
    # db.session.commit()
    import json
    data_x = []
    data_y = []
    data_x_lable = []
    d = bar_1.query.all()
    for i in d:
        data_x.append(i.x)
        data_y.append(i.y)
        data_x_lable.append(i.x_lable)

    data_x_lable = json.dumps(data_x_lable)
    data_x = json.dumps(data_x)
    data_y = json.dumps(data_y)
    return render_template("index.html", data_y=data_y, data_x=data_x, data_x_lable=data_x_lable, d=d)


if __name__ == '__main__':
    app.run(debug=True)
